<?php
class UserModel extends Model{
    //定义表名
    public $table = 'user';

    //表单验证
    public $validate = array(
        //用户名验证
        array('username','nonull','用户名不能为空',1,3),
        array('username','minlen:6','用户名不能少于六位',1,3),
        //密码验证
        array('userpass','nonull','密码不能为空',1,3),
        array('userpass','minlen:6','密码不能少于6位',1,3),
        //二次密码验证
        array('ruserpass','nonull','密码不能为空',1,3),
        array('ruserpass','confirm:userpass','两次输入密码不同',1,3),
        //邀请码验证
        array('invt','nonull','邀请码不能为空',1,3),
        //手机号
        array('mobile','phone','手机号码错误',3,3),
        //昵称
        array('nick','minlen:2','昵称过短',3,3),
        array('nick','maxlen:12','昵称过长',3,3),
        //邮箱
        array('email','email','邮箱错误',3,3),
        //QQ
        array('qq','minlen:4','QQ号码错误',3,3),
        //原始密码
        array('yuserpass','nonull','密码不能为空',1,3),

    );

    //查询一条用户详情
    public function userone($where){
        return $this -> where($where) -> find();
    }

    //添加用户
    public function adduser($data){
        return $this -> add($data);
    }

    //查询邀请码
    public function codeone($where){
        return $this -> table('invcode') -> where($where) -> find();
    }

    //删除邀请码
    public function codedel($where){
        return $this -> table('invcode') -> where($where) -> del();
    }

    //修改用户资料
    public function upinfo($where,$data){
        return $this -> where($where) -> save($data);
    }

    //查询一条登陆信息
    public function selclog($where){
        return $this -> table('loginlog') -> where($where) -> find();
    }

    //修改登陆信息
    public function uplog($where,$data){
        return $this -> table('loginlog') -> where($where) -> save($data);
    }

    //添加登陆信息
    public function addlog($data){
        return $this -> table('loginlog') -> add($data);
    }

}